var MouseManager = function()
{
	var mouse = new Object();
		mouse.x = 0;
		mouse.y = 0;
		mouse.press = false;
		
	this.iniciar = false;
	this.instru = false;
	this.credits = false;
	
	this.countH = 0;
	
	function _mouseMove(e) 
	{
		mouse.x = e.x;
		mouse.y = e.y;
		
		if(mouse.x > 100 && mouse.x < 255 &&
		   mouse.y > 255 && mouse.y < 321 && 
		   sceneManager.currentScene == "opening")
		{
			this.iniciar = true;
			sceneManager.num = 1;
		}
		else
			this.iniciar = false;
		
		if(mouse.x > 137 && mouse.x < 286 &&
		   mouse.y > 382 && mouse.y < 437 && 
		   sceneManager.currentScene == "opening")
		{
			this.instru = true;
			sceneManager.num = 3;
		}
		else
			this.instru = false;
		
		if(mouse.x > 227 && mouse.x < 375 &&
		   mouse.y > 309 && mouse.y < 374 && 
		   sceneManager.currentScene == "opening")
		{
			this.credits = true;
			sceneManager.num = 2;
		}
		else
			this.credits = false;
			
		if(!this.iniciar && !this.instru && !this.credits && 
		   sceneManager.currentScene == "opening")
		{
			sceneManager.num = 0;
		}
		
		if(mouse.x > 18 && mouse.x < 69 &&
		   mouse.y > 548 && mouse.y < 598 &&
		   sceneManager.currentScene == "credits")
		{
			sceneManager.back = 1;
		}
		else 
			sceneManager.back = 0;
		
		if(mouse.x > 749 && mouse.x < 799 &&
		   mouse.y > 548 && mouse.y < 598 &&
		   sceneManager.currentScene == "credits")
		{
			sceneManager.av = 1;
		}
		else 
			sceneManager.av = 0;
			
		if(mouse.x > 18 && mouse.x < 69 &&
		   mouse.y > 548 && mouse.y < 598 &&
		   sceneManager.currentScene == "instructions")
		{
			sceneManager.back_i = 1;
		}
		else 
			sceneManager.back_i = 0;
		
		if(mouse.x > 749 && mouse.x < 799 &&
		   mouse.y > 548 && mouse.y < 598 &&
		   sceneManager.currentScene == "instructions")
		{
			sceneManager.av_i = 1;
		}
		else 
			sceneManager.av_i = 0;

		if(mouse.x > 710 && mouse.x < 750 &&
		   mouse.y > 70 && mouse.y < 105 &&
		   sceneManager.currentScene == "intro")
		{
			sceneManager.close = true;
		}
		else
			sceneManager.close = false;
			
		if(mouse.x > 383 && mouse.x < 443 &&
		   mouse.y > 548 && mouse.y < 598 &&
		   sceneManager.currentScene == "history")
		{
			sceneManager.av_h = 1;
		}
		else
			sceneManager.av_h = 0;
			
		if(mouse.x > 708 && mouse.x < 758 &&
		   mouse.y > 548 && mouse.y < 598 &&
		   sceneManager.currentScene == "congratulation")
		{
			sceneManager.av_c = 1;
		}
		else
			sceneManager.av_c = 0;
			
		if(mouse.x > 728 && mouse.x < 778 &&
		   mouse.y > 548 && mouse.y < 598 &&
		   sceneManager.currentScene == "carta")
		{
			sceneManager.av_carta = 1;
		}
		else 
			sceneManager.av_carta = 0;
			
		if(mouse.x > 729 && mouse.x < 777 &&
		   mouse.y > 548 && mouse.y < 598 &&
		   sceneManager.currentScene == "gameOver")
		{
			sceneManager.av_g = 1;
		}	
		else
			sceneManager.av_g = 0;
			
		console.log("X: " + mouse.x);
		console.log("Y: " + mouse.y);
	}
	
	function _mouseUp(e) 
	{
		switch (e.button)
		{
		}
	}

	function _mouseDown(e) 
	{
		switch (e.button)
		{
			case 0:
				if(mouse.x > 100 && mouse.x < 255 &&
				   mouse.y > 255 && mouse.y < 321 && 
				   sceneManager.currentScene == "opening")
				{
					sceneManager.Intro();
				}
				if(mouse.x > 227 && mouse.x < 375 &&
				   mouse.y > 309 && mouse.y < 374 && 
				   sceneManager.currentScene == "opening")
				{
					sceneManager.Instructions();
				}
				
				if(mouse.x > 137 && mouse.x < 286 &&
				   mouse.y > 382 && mouse.y < 437 && 
				   sceneManager.currentScene == "opening")
				{
					sceneManager.Credits();
				}
				
				if(mouse.x > 18 && mouse.x < 69 &&
				   mouse.y > 548 && mouse.y < 598 &&
				   sceneManager.currentScene == "credits")
				{
					sceneManager.setup();
				}
				
				if(mouse.x > 749 && mouse.x < 799 &&
				   mouse.y > 548 && mouse.y < 598 &&
				   sceneManager.currentScene == "credits")
				{
					sceneManager.Intro();
				}
				
				if(mouse.x > 18 && mouse.x < 69 &&
				   mouse.y > 548 && mouse.y < 598 &&
				   sceneManager.currentScene == "instructions")
				{
					sceneManager.setup();
				}
				
				if(mouse.x > 749 && mouse.x < 799 &&
				   mouse.y > 548 && mouse.y < 598 &&
				   sceneManager.currentScene == "instructions")
				{
					sceneManager.Intro();
				}
				
				if(mouse.x > 698 && mouse.x < 731 &&
				   mouse.y > 551 && mouse.y < 580 &&
				   sceneManager.currentScene == "intro" || 
				   mouse.x > 698 && mouse.x < 731 &&
				   mouse.y > 551 && mouse.y < 580 && 
				   sceneManager.currentScene == "game" || 
				   mouse.x > 698 && mouse.x < 731 &&
				   mouse.y > 551 && mouse.y < 580 && 
				   sceneManager.currentScene == "history" ||
				   mouse.x > 698 && mouse.x < 731 &&
				   mouse.y > 551 && mouse.y < 580 && 
				   sceneManager.currentScene == "opening")
				{
					sceneManager.audio = false;
					sceneManager.count++;
				}
				
				if(sceneManager.count >= 2)
				{
					sceneManager.audio = true;
					sceneManager.count = 0;
				}
				
				if(mouse.x > 744 && mouse.x < 775 &&
				   mouse.y > 551 && mouse.y < 580 &&
				   sceneManager.currentScene == "intro" || 
				   mouse.x > 744 && mouse.x < 775 &&
				   mouse.y > 551 && mouse.y < 580 && 
				   sceneManager.currentScene == "game" ||
				   mouse.x > 744 && mouse.x < 775 &&
				   mouse.y > 551 && mouse.y < 580 && 
				   sceneManager.currentScene == "history")
				{
					sceneManager.pause = true;
					sceneManager.countP++;
				}
				
				if(sceneManager.countP >= 2)
				{
					sceneManager.pause = false;
					sceneManager.countP = 0;
				}
				
				if(mouse.x > 710 && mouse.x < 750 &&
				   mouse.y > 70 && mouse.y < 105 &&
				   sceneManager.currentScene == "intro")
				{
					sceneManager.History();
				}
				
				if(mouse.x > 383 && mouse.x < 443 &&
				   mouse.y > 548 && mouse.y < 598 &&
				   sceneManager.currentScene == "history")
				{
					sceneManager.countH++
					sceneManager.dialogo1 = true;
				}
				
				if(sceneManager.countH >= 2)
				{
					sceneManager.dialogo1 = false;
					sceneManager.dialogo2 = true;
				}
				
				if(sceneManager.countH >= 3)
				{
					sceneManager.dialogo1 = false;
					sceneManager.dialogo2 = false;
					sceneManager.dialogo3 = true;
				}
				
				if(sceneManager.countH >= 4)
				{
					sceneManager.dialogo1 = false;
					sceneManager.dialogo2 = false;
					sceneManager.dialogo3 = false;
					sceneManager.countH = 0;
					sceneManager.Game();
				}
								
				if(mouse.x > 729 && mouse.x < 777 &&
				   mouse.y > 548 && mouse.y < 598 &&
				   sceneManager.currentScene == "gameOver")
				{
					sceneManager.Opening();
				}				
				
				if(mouse.x > 729 && mouse.x < 777 &&
				   mouse.y > 548 && mouse.y < 598 &&
				   sceneManager.currentScene == "carta")
				{
					sceneManager.Opening();
				}
				
				if(mouse.x > 708 && mouse.x < 758 &&
				   mouse.y > 548 && mouse.y < 598 &&
				   sceneManager.currentScene == "congratulation")
				{
					sceneManager.Carta();
				}
			break;
		}
	}

	graphics.canvas.addEventListener('mousemove', _mouseMove, false);
	graphics.canvas.addEventListener('mouseup', _mouseUp, false);
	graphics.canvas.addEventListener('mousedown', _mouseDown, false);
}

var mouseManager = new MouseManager();